<template>
  <div class="bg-white">
    <div class="container-title">
      <span class="big">账号返利:{{availableRebate}}</span>
    </div>
    <homeTable
        :list="list" :translate='100'
        @getData="getData"
        @onPageSizeChange="onPageSizeChange"
        @onPageChange="onPageChange"
      />
    </TabPane>
  </div>
</template>
<script>
  import homeTable from '@/components/homeTable'

  export default {
    props: {
      form: {
        type: Object
      }
    },
    components: {
      homeTable
    },
    data() {
      return {
        list: {
          status: 'pass',
          totalItem: 1,
          pageSize: window.$pageSize,
          currentPage: 1,
          columns: [{
            title: '变更单号',
            key: 'orderNo',
            align: 'left',
          }, {
            title: '变更时间',
            key: 'createDate',
            align: 'left',
          }, {
            title: '变更前返利金额',
            key: 'beforeRebate',
            align: 'left',
          }, {
            title: '变更后返利金额',
            key: 'afterRebate',
            align: 'left',
          }, {
            title: '变更返利金额',
            key: 'changeRebate',
            align: 'left',
          }, {
            title: '变更方向',
            key: 'directionName',
            align: 'left'
          }, {
            title: '变更备注',
            key: 'remark',
            align: 'left',
          }, {
            title: '任务是否完成',
            key: 'isComplete',
            align: 'left',
            render: (h, p) => {
              return p.row.isComplete ? '已完成' : '未完成'
            }
          }, {
            title: '审核备注',
            key: 'auditIntegralRemark',
            align: 'left',
          }],
          data: [{}]
        },
        availableRebate: 0
      }
    },
    mounted () {
      this.getData()
    },
    methods: {
      getData() {
        let storeId = this.form.storeDTO.id
        if(!storeId) return
        let param = {
          current: this.list.currentPage,
          size: this.list.pageSize,
          storeId
        };
        this.list.status = "loading";
        this.$ajaxGet(`/contract_store/detail_rebate_list/${storeId}`, param).then(res => {
          this.availableRebate = res.availableRebate
          let data = res.storeRebateAccountChangeLogQuery
          this.list.totalItem = Number(data.total);
          this.list.data = (data.records || []).map(item => {
            return {
              auditIntegralRemark: item.auditIntegralRemark,
              isComplete: item.isComplete,
              ...item.storeRebateAccountChangeLogDTO
            }
          })
          this.list.status = "pass";
        })
        .catch(() => {
          this.list.status = "pass";
        });
      },
      onPageChange(number) {
        this.list.currentPage = number;
        this.getData();
      },
      onPageSizeChange(pageSize) {
        this.list.currentPage = 1;
        this.list.pageSize = pageSize;
        this.getData();
      },
    },
    computed: {

    }
  }
</script>
